
#include "myRecv.h"


MyRecv::MyRecv( int chid, int value, int value_sec, int value_nsec ):chid(chid), value(value), value_sec(value_sec), value_nsec(value_nsec){

}

MyRecv::~MyRecv(){

}

void MyRecv::execute(void*){

	running = true;

	timerChanneID = ChannelCreate(0);
	timer = new Timer();

	while (running){

		struct _pulse pulse;
		if(-1 == MsgReceivePulse(timerChanneID, &pulse, sizeof(pulse), NULL)){
			perror("error");
			exit(1);
		}

		int connectionID = ConnectAttach(0, 0, chid, 0, 0);
		MsgSendPulse( connectionID, SIGEV_PULSE_PRIO_INHERIT, _PULSE_CODE_MINAVAIL, value);
		ConnectDetach(connectionID);
	}
}

Timer* MyRecv::getInstance(){
	return timer;
}

void MyRecv::startTimer(){
	timer->addTimer(timerChanneID, value_sec, value_nsec, 0, 0);
}

void MyRecv::shutdown(){
	running = false;

}
